home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 3.1.2
- +
- +
- + basic.h
- +
- +
- + Copyright (c) 1995 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 66123 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
- #ifndef LEDA_BASIC_H
- #define LEDA_BASIC_H
-
- #include <stdlib.h>
-
- //------------------------------------------------------------------------------
- // compiler/system dependent definitions and includes
- //------------------------------------------------------------------------------
-
- #if defined(__SVR4) || defined(__SVR4__)
- #define __svr4__
- #endif
-
- // g++ (version < 2.6), bcc, and ztc cannot handle template functions correctly
- // and we have to use the LEDA_TYPE_PARAMETER macro for class type arguments.
- // (see <LEDA>/prog/basic/param.c for an example)
-
- #define __TEMPLATE_FUNCTIONS__
-
- #if (__GNUC__ == 2 && __GNUC_MINOR__ < 6 ) || defined(__ZTC__) || defined(__BORLANDC__)
- #undef __TEMPLATE_FUNCTIONS__
- #endif
-
- // currently only g++ (>= 2.6) has a built-in boolean type
-
- #if (__GNUC__ > 1 && __GNUC_MINOR__ > 5)
- #define __BUILTIN_BOOL__
- #endif
-
-
- // begin_cdr
- // Amiga GCC 2.6.3 has inconsistent include files
-
- #if defined(AMIGA)
- #define MAXFLOAT FLT_MAX
- #define MAXDOUBLE DBL_MAX
- #define MINFLOAT FLT_MIN
- #define MINDOUBLE DBL_MIN
- // value of AHZ (<sys/acct.h>)
- #define HZ 64
- #endif
- // end_cdr
-
-
- // linux defines random as a macro
- #if defined(random)
- #undef random
- #endif
-
-
- // we assume that ztc and wcc are used under DOS
-
- #if defined(__ZTC__) || defined(__WATCOMC__)
- #define __MSDOS__
- #endif
-
-
-
- // DOS and EMX have no <values.h>
-
- #if defined(__MSDOS__) || defined(__EMX__)
- #define MAXINT (int(0x7FFFFFFF))
- #define MAXFLOAT (float(3.37E+38))
- #define MAXDOUBLE (double(1.797693E+308))
- #else
- #include <values.h>
- #endif
-
-
- // EMX and WCC have no PI in <math.h>
- #if defined(__WATCOMC__) || defined (__EMX__)
- #define M_PI 3.14159265358979323846
- #endif
-
-
- // ztc header files end with .hpp
- #if defined(__ZTC__)
- #include <iostream.hpp>
- #else
- #include <iostream.h>
- #endif
-
-
-
- //------------------------------------------------------------------------------
- // Global Types
- //------------------------------------------------------------------------------
-
- typedef void* GenPtr; // generic pointer type
-
- enum rel_pos { before = 1, after = 0 };
- enum direction { forward = 0, backward = 1 };
-
- #define nil 0
-
-
- //------------------------------------------------------------------------------
- // STRINGIZE: turning a macro argument into a string
- //------------------------------------------------------------------------------
-
- #if defined(__STDC__) || defined(__MSDOS__)
- #define STRINGIZE(x) #x
- #else
- #define STRINGIZE(x) "x"
- #endif
-
-
- //------------------------------------------------------------------------------
- // automatically included LEDA header files
- //------------------------------------------------------------------------------
-
- #include <LEDA/leda.h>
- #include <LEDA/error.h>
- #include <LEDA/memory.h>
- #include <LEDA/param_types.h>
- #include <LEDA/handle_types.h>
- #include <LEDA/bool.h>
- #include <LEDA/string.h>
- #include <LEDA/random.h>
- #include <LEDA/misc.h>
-
-
-
- //------------------------------------------------------------------------------
- // Defining Linear Orders
- //------------------------------------------------------------------------------
-
- #define DEFINE_LINEAR_ORDER(type,cmp,new_type)\
- struct new_type : public type\
- { new_type(type s) : type(s) {}\
- new_type(const new_type& s) : type(s) {}\
- new_type() {}\
- ~new_type() {}\
- };\
- inline int compare(const new_type& x, const new_type& y) { return cmp(x,y); }
-
-
- // INT<cmp>: int with user defined linear order cmp
-
- typedef int (*CMP_INT_TYPE)(const int&, const int&);
-
-
- template<CMP_INT_TYPE cmp> class INT {
-
- int p;
-
- public:
- INT(const int i=0) { p = i;}
- operator int() { return p; }
-
- friend void Print(const INT<cmp>& x, ostream& out) { out << x.p; }
- friend void Read(INT<cmp>& x, istream& in) { in >> x.p; }
- friend void Init(INT<cmp>& x) { x.p=0; }
- friend GenPtr Copy(const INT<cmp>& x) { return GenPtr(x); }
- friend void Clear(INT<cmp>& x) { x.p = 0; }
- friend GenPtr Convert(const INT<cmp>& x) { return GenPtr(x.p); }
- friend INT<cmp>& Access(INT<cmp>*,const GenPtr& p) { return *(INT<cmp>*)&p; }
- friend int compare(const INT<cmp>& x, const INT<cmp>& y) { return cmp(x.p,y.p);}
- };
-
-
-
- //------------------------------------------------------------------------------
- // ITERATION
- //------------------------------------------------------------------------------
-
- #define forall_items(x,S) for(x = (S).first_item(); x; x = (S).next_item(x) )
-
- /*
- To avoid multiple declarations of the "forall_loop_item" variable
- we use a dummy for-loop to create a new scope for it.
- This, however, does not work with all compilers (ztc,lucid ...)
- and we have to use the old forall mechanism (no nesting).
- */
-
- #if defined(__ZTC__) || defined(__lucid)
-
- #define forall(x,S)\
- for((S).start_iteration(); (S).read_iterator(x); (S).move_to_succ())
-
- #define Forall(x,S)\
- for((S).Start_iteration(); (S).read_iterator(x); (S).move_to_pred())
-
- #else
-
- #define forall(x,S)\
- for(LEDA::loop_dummy=0; LEDA::loop_dummy<1; LEDA::loop_dummy++)\
- for(GenPtr forall_loop_item=(S).first_item();\
- (S).forall_loop_test(forall_loop_item,x);\
- (S).loop_to_succ(forall_loop_item))
-
- #define Forall(x,S)\
- for(LEDA::loop_dummy=0; LEDA::loop_dummy<1; LEDA::loop_dummy++)\
- for(GenPtr forall_loop_item=(S).last_item();\
- (S).forall_loop_test(forall_loop_item,x);\
- (S).loop_to_pred(forall_loop_item))
-
- #endif
-
-
-
- #endif
-